//
//  Kratos_TitleTableViewCell.m
//  kk_framework
//
//  Created by 7yao.top on 2018/11/5.
//  Copyright © 2018年 7yao.top. All rights reserved.
//

#import "Kratos_TitleTableViewCell.h"
#import "Masonry.h"
#import "Kratos_TableViewControllerConst.h"
#import "Kratos_titleCellModel.h"

@interface Kratos_TitleTableViewCell()
@property (nonatomic, weak)NSLayoutConstraint *arrowWidthContraint;
@property (nonatomic, weak)NSLayoutConstraint *arrowHeightContraint;
@property (nonatomic, weak)NSLayoutConstraint *arrowRightContraint;

@end

@implementation Kratos_TitleTableViewCell

+ (Kratos_BaseTableViewCell *)Kratos_cellWithIdentifier:(NSString *)cellIdentifier Kratos_tableView:(UITableView *)tableView
{
    Kratos_TitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if(cell == nil){
        cell = [[Kratos_TitleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)Kratos_setupUI
{
    [super Kratos_setupUI];
    //添加右边剪头
    UIImageView *arrow = [[UIImageView alloc] init];
    arrow.frame = CGRectZero;
    arrow.translatesAutoresizingMaskIntoConstraints = NO;
    [self.contentView addSubview:arrow];
    self.arrow = arrow;
    //设置图片约束
    [self Kratos_setupArrowImageConstraints];
}
- (void)Kratos_setupArrowImageConstraints
{
    
    

    
    
    NSLayoutConstraint *arrowRightContraint = [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-Kratos_KCellMargin];
    [self.contentView addConstraint:arrowRightContraint];
    self.arrowRightContraint = arrowRightContraint;
    
    
    NSLayoutConstraint *arrowWidthContraint = [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:Kratos_KArrowWidth];
    [self.contentView addConstraint:arrowWidthContraint];
    self.arrowWidthContraint = arrowWidthContraint;
    
    
    NSLayoutConstraint *arrowHeightContraint = [NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:Kratos_kArrowHeight];
    
    [self.contentView addConstraint:arrowHeightContraint];
    self.arrowHeightContraint = arrowHeightContraint;
    
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.arrow attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    
}


- (void)Kratos_setupDataModel:(Kratos_baseCellModel *)model
{
    [super Kratos_setupDataModel:model];
    Kratos_titleCellModel *cellModel = (Kratos_titleCellModel *)model;
    if(cellModel.attributeTitle){
        self.textLabel.attributedText = cellModel.attributeTitle;
    }else{
        self.textLabel.text = cellModel.title;
        self.textLabel.textColor = cellModel.titleColor;
        self.textLabel.font = cellModel.titleFont;
    }
    self.textLabel.textAlignment = cellModel.titileTextAlignment;
    self.imageView.image = cellModel.icon;
    
    
    self.arrow.hidden = !cellModel.showArrow;
    self.selectionStyle = cellModel.Kra_selectionStyle;
    self.arrow.image = cellModel.arrowImage;
    
    self.imageView.image = cellModel.icon;
    
    self.arrowWidthContraint.constant = cellModel.arrowWidth;
    self.arrowHeightContraint.constant = cellModel.arrowHeight;
    self.arrowRightContraint.constant = - cellModel.controlRightOffset;

}

@end
